package org.codegallery.dynawebappgal.web;

import java.util.Map;

import javax.inject.Inject;

import org.codegallery.dynawebappgal.dto.UserDTO;
import org.codegallery.dynawebappgal.service.UserRegService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

@Controller
public class RegisterController {
	private UserRegService userRegService;
	
	
	
	public UserRegService getUserRegService() {
		return userRegService;
	}

	public void setUserRegService(UserRegService userRegService) {
		this.userRegService = userRegService;
	}
	
	@Inject
	public RegisterController(UserRegService userRegService){
		this.userRegService=userRegService;
	}

	@RequestMapping({ "/", "/reg" })
	public String showHomePage(Map<String, Object> model) {
		UserDTO user=new UserDTO();
		model.put("user",user);
		return "reg";
	}
	
	@RequestMapping({ "/", "/regProcess" })
	public String regProcess(@ModelAttribute("user") UserDTO user,Map<String, Object> model) {
		System.out.println(user.getUsername());
		if(userRegService.saveUser(user)){
			return "home";
		}else{
			return "reg";
		}
	}
}
